home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / slip / sun / csn-slip-package / tools / killslip.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-16  |  1.1 KB  |  64 lines

  1.  
  2. #include <sys/types.h>
  3. #include <sys/file.h>
  4. #include <sys/dir.h>
  5. #include <errno.h>
  6. #include <stdio.h>
  7.  
  8. #define LOCKDIRNAME    "/usr/spool/locks/LCK..%s"    /**/
  9. #define DEFTTY "cuab"
  10.  
  11. /* 
  12.  */
  13.  
  14. extern int errno;
  15.  
  16. main(ac,av)
  17. int ac;
  18. char **av;
  19. {
  20.     int fd, pid, a;
  21.     char tbuf[sizeof(LOCKDIRNAME) + MAXNAMLEN];
  22.  
  23.     (void)sprintf(tbuf,LOCKDIRNAME,"slip");
  24.  
  25.     if ((a  = access(tbuf,F_OK)) == 0) {
  26.         (void)
  27.         fprintf
  28.         (stderr,"killslip: No action because LCK..slip exists\n");
  29.         exit(1);
  30.     }
  31.  
  32.     if (ac == 2)
  33.         (void)sprintf(tbuf, LOCKDIRNAME, *++av);
  34.     else
  35.         (void)sprintf(tbuf, LOCKDIRNAME, DEFTTY);
  36.  
  37.     /*
  38.      * file is already locked
  39.      * check to see if the process holding the lock still exists
  40.      */
  41.     fd = open(tbuf, O_RDWR, 0);
  42.  
  43.     if (fd < 0) {
  44.         perror("killslip: open(LCK..cuab)");
  45.         exit(1);
  46.     }
  47.     if (read(fd, &pid, sizeof(pid)) != sizeof(pid)) {
  48.         (void)close(fd);
  49.         perror("killslip: read()");
  50.         exit(1);
  51.     }
  52.  
  53.     if (kill(pid, 1) == 0 ) {
  54.         fprintf(stderr,"killslip: sent HANGUP signal to %d\n",pid);
  55.         (void)close(fd);    /* process is still running */
  56.         exit(0);
  57.     }
  58.  
  59.     perror("killslip: kill()");
  60.  
  61.     exit(1);
  62. }
  63.  
  64.